package j09gouzao;

class Cat {
    String name;
    int age;
    String sex;

    //构造方法 - 特殊，目的：方便给属性赋值
    //没有返回值，也不能写，方法名和类名相同
    //在new的时候，会自动调用
    public Cat(){
        System.out.println("Cat 构造方法");
    }
    //赋值，支持重载
    public Cat(String name,int age,String sex){
        System.out.println("有参数的构造");
        this.name = name;
        this.age = age;
        this.sex = sex;
    }

}
class CatTest{
    public static void main(String[] args) {
//        Cat c1 = new Cat();
//        c1.age = 3;
//        c1.name = "波斯猫";
//        c1.sex="男";

        Cat c2 = new Cat("加菲猫",2,"公");
        System.out.println("c2.name = " + c2.name);
        System.out.println("c2.age = " + c2.age);
        System.out.println("c2.sex = " + c2.sex);
    }
}

